﻿Imports SecretaryToolData

Public Class frmMobileProviders

	Private Sub frmMobileProviders_Load(sender As Object, e As System.EventArgs) Handles Me.Load
		LoadInitialData()
	End Sub

	Private Sub LoadInitialData()

		cmboProviders.DisplayMember = Extensions.GetMemberInfo(Function(x As VM_MobileProvider) x.ServiceProvider).Name
		cmboProviders.ValueMember = Extensions.GetMemberInfo(Function(x As VM_MobileProvider) x.ProviderID).Name
		cmboProviders.DataSource = VM_MobileProvider.AllMobileProviders

	End Sub

	Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
		Dim newMobileProvider = New VM_MobileProvider()

		LoadInitialData()

		cmboProviders.SelectedValue = newMobileProvider.ProviderID
	End Sub

	Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
		Me.Close()
	End Sub

	Private Sub cmboProviders_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cmboProviders.SelectedIndexChanged
		Try
			If cmboProviders.SelectedValue IsNot Nothing Then
				MobileProviderBindingSource.DataSource = New VM_MobileProvider(cmboProviders.SelectedValue)
				MobileProviderBindingSource.ResetBindings(False)
			End If
		Catch ex As Exception
			'the valuemember isn't set yet, so the lookup is invalid
		End Try
	End Sub
End Class